package com.yunxi.controller.sto;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sto.pojo.StoStorageStaffVO;
import com.yunxi.sto.service.StoStorageStaffDubboService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 仓储人员 前端控制器
 * </p>
 * @author caoYong
 * @since 2019-06-06
 */
@RestController
@RequestMapping("/admin/stoStorageStaff")
@Api(tags = "sto:storageStaff", description = "仓储人员接口")
public class StoStorageStaffController {
    private static final Logger logger = LoggerFactory.getLogger(StoStorageStaffController.class);

    @Autowired
    StoStorageStaffDubboService stoStorageStaffDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询分页")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
    })
    public ApiResult page(StoStorageStaffVO stoStorageStaffVO, Integer pageNum, Integer pageSize) throws Exception {
        return ResponseUtil.ok(stoStorageStaffDubboService.findPageByVO(stoStorageStaffVO, pageNum, pageSize));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个")
    @ApiImplicitParam(paramType = "query", name = "storageStaffId", value = "主键id", required = true, dataType = "String")
    public ApiResult load(String storageStaffId, @CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(stoStorageStaffDubboService.getById(storageStaffId));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存信息")
    public ApiResult save(@RequestBody StoStorageStaffVO stoStorageStaffVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        stoStorageStaffDubboService.saveOrUpdate(stoStorageStaffVO);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/del")
    @ApiOperation(value = "停用")
    public ApiResult del(@RequestBody @ApiParam(value = "主键id集合") List<String> list, @CurrentUser LoginInfo loginInfo) throws Exception {
        stoStorageStaffDubboService.delAndReset(list, "0",loginInfo.getUserCode());
        return ResponseUtil.ok("success");
    }

    @PostMapping("/reset")
    @ApiOperation(value = "启用")
    public ApiResult reset(@RequestBody @ApiParam(value = "主键id集合") List<String> list, @CurrentUser LoginInfo loginInfo) throws Exception {
        stoStorageStaffDubboService.delAndReset(list, "1",loginInfo.getUserCode());
        return ResponseUtil.ok("success");
    }

    @GetMapping("/staffList")
    @ApiOperation(value = "仓储人员列表")
    public ApiResult staffList() throws Exception {
        List<StoStorageStaffVO> list = stoStorageStaffDubboService.staffList();
        return ResponseUtil.ok(list);
    }

    @GetMapping("/export")
    @ApiOperation(value = "导出")
    public ApiResult export(StoStorageStaffVO stoStorageStaffVO) throws Exception {
        return ResponseUtil.ok(stoStorageStaffDubboService.export(stoStorageStaffVO));
    }

    @GetMapping("/getStaffList")
    @ApiOperation(value = "获取仓储人员")
    @ApiImplicitParam(paramType = "query", name = "positionCode", value = "职位代码", required = false, dataType = "String")
    public ApiResult getStaffList(String positionCode,@CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(stoStorageStaffDubboService.getStaffList(positionCode,loginInfo.getPartnerCode()));
    }
}
